import Cookies from 'js-cookie'
import store from '@/store'

const TokenKey = 'measure_admin_token'
const UserKey = 'measure_admin_user'
const LeftMenuKey = 'measure_left_menu'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

////////////
export function getUser() {
  // const userValue = Cookies.get(UserKey)
  // if (userValue != null) {
  //   return JSON.parse(JSON.parse(userValue))
  // } else {
  //   return null
  // }
  const value = localStorage.getItem(process.env.VUE_APP_BASE_API + UserKey)
  if (value != null) {
    return JSON.parse(JSON.parse(value))
  } else {
    return null
  }
}

export function setUser(user) {
  localStorage.setItem(process.env.VUE_APP_BASE_API + UserKey, JSON.stringify(user))
  // return Cookies.set(UserKey, JSON.stringify(user))
}

export function removeUser() {
  return Cookies.remove(process.env.VUE_APP_BASE_API + UserKey)
}
